home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / bakzap.zip / BAKZAP.C < prev    next >
C/C++ Source or Header  |  1988-12-08  |  3KB  |  139 lines

  1. /*
  2. Backspace zapper by Mat*Rat
  3.  
  4. Ever have CAPTURE on while you're entering messages on line?
  5. Ever get those stupid backspace characters in your capture
  6. file?  Pain, isn't it?  BAKZAP will read any input text file
  7. you specify and ZAP all the backspace characters.  In other
  8. words, it acts just like the bulletin board, zapping characters
  9. from the file that would have been replaced by backspace
  10. keypresses.  If no backspaces are found, the file is left
  11. unmodified.  If backspaces are found, the output goes to a
  12. file called TEMP.  When all done, the original file is deleted,
  13. and TEMP is renamed to the original filename.
  14. */
  15.  
  16. #include <stdio.h>
  17. #include <string.h>
  18.  
  19. #define DEBUG 0
  20.  
  21. main(argc, argv)
  22. int argc;
  23. char *argv[];
  24. {
  25.  
  26. char filename[40];
  27. char works[120], *wPtr;
  28. char oworks[120];
  29. char temp[80];
  30. int i, j;
  31. long bakzaps;
  32. FILE *fPtr, *oPtr;
  33.  
  34. bakzaps = 0;
  35.  
  36. if (argc == 1)
  37.   {
  38.   printf("\nInput filename to zap backspaces from? ");
  39.   gets(filename);
  40.   }
  41. else
  42.   strcpy(filename, argv[1]);
  43.  
  44. strupr(filename);
  45. strcpy(temp, filename);
  46. wPtr = strrchr(temp, 92); /* Path specifier? */
  47.  
  48. if (wPtr == NULL)
  49.   wPtr = strchr(temp, ':'); /* drive specifier? */
  50.  
  51. if (wPtr != NULL)
  52.   {
  53.   wPtr++;
  54.   *wPtr = 0;
  55.   }
  56. else
  57.   temp[0] = 0;
  58.  
  59. strcat(temp, "TEMP.TXT");
  60.  
  61. fPtr = fopen(filename, "r");
  62. if (fPtr == NULL)
  63.   {
  64.   printf("\nBAKZAP can't open file: %s\n", filename);
  65.   return;
  66.   }
  67.  
  68. oPtr = fopen(temp, "w");
  69.  
  70. if (oPtr == NULL)
  71.   {
  72.   fclose(fPtr);
  73.   return;
  74.   }
  75.  
  76. do
  77.   {
  78.   wPtr = fgets(works,119,fPtr);
  79.   if (wPtr != NULL)
  80.     {
  81.     if (strlen(works) != 0)
  82.       {
  83.       j = 0;
  84.       i = 0;
  85.       do
  86.         {
  87.         oworks[j] = works[i];
  88.         if ( (works[i] == 8) && (j>0) )
  89.           {
  90.           bakzaps = bakzaps + (long)1;
  91.           j--;
  92.           }
  93.         else
  94.           j++;
  95.         i++;
  96.         }
  97.       while (works[i-1] != 0);
  98.       }
  99.     fputs(oworks, oPtr);
  100.     }
  101.   }
  102. while (wPtr != NULL);
  103.  
  104. fclose( fPtr );
  105. fclose( oPtr );
  106. if (bakzaps == (long)0)
  107.   {
  108.   unlink(temp);
  109.   printf("\nNo backspace characters found in %s\n", filename);
  110.   }
  111. else
  112.   {
  113.   unlink(filename);
  114.   strcpy(works, "rename ");
  115.   strcat(works, temp);
  116.   strcat(works, " ");
  117.   wPtr = strrchr(filename, 92);
  118.   if (wPtr == NULL)
  119.     wPtr = strrchr(filename, ':');
  120.   if (wPtr == NULL)
  121.     wPtr = filename;
  122.   else
  123.     wPtr++;
  124.   strcat(works, wPtr);
  125. #if DEBUG
  126.   printf("System call: %s\n", works);
  127. #else
  128.   system(works);
  129. #endif
  130.   printf("\n%lu backspace characters zapped from file %s\n",bakzaps,filename);
  131.   }
  132.  
  133. puts("Thanks for using BAKZAP by Mat*Rat");
  134. printf("From Ratware Softworks, (c) 1988");
  135.  
  136. }
  137.  
  138.  
  139.